package com.zoshine.zzg.service;

import com.zoshine.zzg.dao.OrderReceiveDetailDao;
import com.zoshine.zzg.exception.AppException;
import com.zoshine.zzg.exception.ErrorMessage;
import com.zoshine.zzg.pojo.OrderReceive;
import com.zoshine.zzg.pojo.OrderReceiveDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 收货单ServicesImlp
 * @author 田沛凌
 * @time 2017年6月28日 下午1:10:53
 */
@Service
@Transactional
public class OrderReceiveService extends BaseService<OrderReceive> {
//	private IdWorker<Long> orderReceiveIdWork;
//	private OrderReceiveDao orderReceiveDao;
	private OrderReceiveDetailDao orderReceiveDetailDao;
//	private GoodsDao goodsDao;
//
//	@Autowired
//	public void setOrderReceiveDao(OrderReceiveDao orderReceiveDao) {
//		this.orderReceiveDao = orderReceiveDao;
//	}
//	@Autowired
//	public void setOrderReceiveIdWork(IdWorker<Long> orderReceiveIdWork) {
//        this.orderReceiveIdWork = orderReceiveIdWork;
//    }
	@Autowired
    public void setOrderReceiveDetailDao(OrderReceiveDetailDao orderReceiveDetailDao) {
        this.orderReceiveDetailDao = orderReceiveDetailDao;
    }
//	@Autowired
//    public void setGoodsDao(GoodsDao goodsDao) {
//        this.goodsDao = goodsDao;
//    }
//    @Override
//	public void delOrderReceive(Long receiveId) {
//		if(receiveId == null){
//			throw new AppException(ErrorMessage.ORDER_RECEIVE_ID_CAN_NOT_NULL);
//		}
//		orderReceiveDao.delete(receiveId);
//	}
//
//	@Override
//	public void addOrderReceive(OrderReceive orderReceive) {
//	    //新增收货单
//		orderReceive.setReceiveId(orderReceiveIdWork.createId());
//		orderReceive.setStatus(OrderReceiveStatus.PENDINGRECEIVE.getValue());
//		orderReceive.setCreateTime(new Date());
//		orderReceive.setUpdateTime(new Date());
//		//收货明细
//		List<OrderReceiveDetail> listDetail=new ArrayList<OrderReceiveDetail>();
//		OrderReceiveDetail orderReceiveDetai=null;
//		Integer totalCount=0;
//		Integer totalSell=0;
//		Integer totalSettlementPrice=0;
//		for (IdAndCount  idAndCount: orderReceive.getIdAndCounts()) {
//		    orderReceiveDetai=new OrderReceiveDetail();
//		    orderReceiveDetai.setOrderReceiveDetailId(orderReceiveIdWork.createId());
//		    orderReceiveDetai.setOrderReceive(orderReceive.getReceiveId());
//		    orderReceiveDetai.setGoodsId(idAndCount.getGoodsId());
//		    orderReceiveDetai.setGoodsCount(idAndCount.getGoodsCount());
//		    listDetail.add(orderReceiveDetai);
//		    Goods goods = goodsDao.selectOne(idAndCount.getGoodsId());
//		    totalCount+=idAndCount.getGoodsCount();
//		    totalSell+=goods.getGoodsSellPrice()*idAndCount.getGoodsCount();
//		    totalSettlementPrice+=goods.getGoodsSettlementPrice()*idAndCount.getGoodsCount();
//		}
//		orderReceive.setTotalCount(totalCount);
//		orderReceive.setTotalSell(totalSell);
//		orderReceive.setTotalSettlementPrice(totalSettlementPrice);
//		orderReceiveDao.insert(orderReceive);
//		orderReceiveDetailDao.batchInsert(listDetail);
//	}
//
//	@Override
//	public OrderReceive getOrderReceive(Long receiveId) {
//		if(receiveId == null){
//			throw new AppException(ErrorMessage.ORDER_RECEIVE_ID_CAN_NOT_NULL);
//		}
//		return orderReceiveDao.selectOne(receiveId);
//	}
//
//	@Override
//	public List<OrderReceive> pageList(OrderReceive orderReceive) {
//		return orderReceiveDao.selectList(orderReceive);
//	}
//
//	@Override
//	public void editOrderReceive(OrderReceive orderReceive) {
//		if(null == orderReceive.getReceiveId()){
//			throw new AppException(ErrorMessage.ORDER_RECEIVE_ID_CAN_NOT_NULL);
//		}
//		orderReceiveDao.update(orderReceive);
//	}
    public List<OrderReceiveDetail> pageOrderReceiveDetail(Long receiveId) {
        if(null == receiveId){
            throw new AppException(ErrorMessage.ORDER_RECEIVE_ID_CAN_NOT_NULL);
        }
        return orderReceiveDetailDao.selectListByReceiveId(receiveId);
    }
//
//
}
